package com.itbour.service.tg.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.common.util.StringUtils;
import com.itbour.dao.tg.TmplSetInfoDao;
import com.itbour.dto.tg.DesignInfoDto;
import com.itbour.dto.tg.TmplSetDto;
import com.itbour.dto.tg.TmplSetRDto;
import com.itbour.dto.tg.TypeInfoDto;
import com.itbour.service.tg.TmplSetInfoService;


/**
 * @author LQ (itb_tmpl_set/itb_tmpl_set_r)
 * Special template purpose implementation classes
 */
public class TmplSetInfoServiceImpl implements TmplSetInfoService {

	private TmplSetInfoDao tmplSetInfoDao;
	
	/**获取模板组
	 */
	public Page tmplSetInfoPg(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = tmplSetInfoDao.selectTmplSetCnt(param);//获取个数
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<TmplSetDto> data = tmplSetInfoDao.selectTmplSetInfo(param);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			//clearSelectDataSource(dataSource);
		}
	}
	
	/**
	 * 获取模板组下的  设计 模板列表
	 */
	public Page getTmplGroupDesignInfo(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = tmplSetInfoDao.getTmplGroupDesignCnt(param);
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<TmplSetRDto> data = tmplSetInfoDao.getTmplGroupDesignInfo(param);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
		}
	}
	
	//获取专题下的PPT-设计模板
	public Page getSpecialPPtInfo(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = tmplSetInfoDao.selectSpecialPPtCnt(param);
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<DesignInfoDto> data = tmplSetInfoDao.getSpecialPPtInfo(param);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
		}
	}
	
	//获取适合某个专题能添加的设计模板信息
	public Page getSuitDesignInfo(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = tmplSetInfoDao.selectSuitDesignCnt(param);
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<DesignInfoDto> data = tmplSetInfoDao.getSuitDesign(param);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
		}
	}
	
	//获取专题下合适的PPT列表信息
	public Page getSuitPPtInfo(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = tmplSetInfoDao.selectSuitPPTCnt(param);
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<DesignInfoDto> data = tmplSetInfoDao.getSuitPPTInfo(param);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
		}
	}
	public List<TypeInfoDto> selectOneType(Map<String, Object> parm){
		return tmplSetInfoDao.selectOneType(parm);
	}
	
	//添加适合的设计模板到专题下
	public boolean addSuitDesign(Map<String, Object> parm){
		try{
			tmplSetInfoDao.addSuitDesign(parm);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	//删除专题设计模板
	public boolean delTmplSRDesign(Map<String, Object> parm){
		try{
			tmplSetInfoDao.delTmplSRInfo(parm);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	//修改专题设计下的order
	public boolean udpTorder(Map<String, Object> parm){
		try{
			tmplSetInfoDao.updTsrOrder(parm);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
	
	//获取模板组信息
	public List<TmplSetDto> selectTmplSetInfo(Map<String,Object> param) {
		return tmplSetInfoDao.selectTmplSetInfo(param);
	}
	
	//删除模板组
	public void delTmplGp(String delIds) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("ids", StringUtils.listToString2(StringUtils.stringToList2(delIds)));
		tmplSetInfoDao.delTmplSInfo(param);
		tmplSetInfoDao.delTmplSRInfo(param);// 一并删除关联信息
	}
	
	//添加模板组
	public void addTmplSet(TmplSetDto topicInfo) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("title", topicInfo.getTitle());
		param.put("desc", topicInfo.getDesc());
		param.put("thumb", topicInfo.getThumb());
		param.put("use", topicInfo.getUse());
		param.put("start_time", topicInfo.getStart_time());
		param.put("end_time", topicInfo.getEnd_time());
		param.put("update_by", topicInfo.getUpdate_by());
		tmplSetInfoDao.insertTmplSInfo(param);
	}
	
	//修改模板组
	public void upTmplSet(Map<String,Object> param) {
		tmplSetInfoDao.updTmplSInfoById(param);
	}
	
	
	
	
	
	
	public TmplSetInfoDao getTmplSetInfoDao() {
		return tmplSetInfoDao;
	}

	public void setTmplSetInfoDao(TmplSetInfoDao tmplSetInfoDao) {
		this.tmplSetInfoDao = tmplSetInfoDao;
	}
}
